package com.longxi.tianjintianbao.ui.adapter.multitype.patrol;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.patrol.Patrol;
import com.longxi.tianjintianbao.utils.TimeComparisonUtils;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class PatrolListViewBinder2 extends ItemViewBinder<Patrol, PatrolListViewBinder2.ViewHolder> {

    OnSelectPatrolListener listener;

    public PatrolListViewBinder2(OnSelectPatrolListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_patrol_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Patrol patrol) {
        holder.mTvAddress.setText("巡检名称:" + patrol.getName() + "\t\t巡检类别:" + patrol.getInspecttype());
        holder.mTvDateperiod.setText("巡检时间:" + TimeComparisonUtils.dateTString(patrol.getStartdate()) + "~" +  TimeComparisonUtils.dateTString(patrol.getEnddate()));
        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(patrol);
            }
        });

        if(TimeComparisonUtils.judgeTimeIsToday(patrol.getStartdate(), patrol.getEnddate())){
            holder.mTvToday.setVisibility(View.VISIBLE);
        }else{
            holder.mTvToday.setVisibility(View.INVISIBLE);
        }

        holder.mTvExplain.setVisibility(View.VISIBLE);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvAddress;
        TextView mTvDateperiod;
        TextView mTvExplain;
        ImageView mIvImage1;
        ImageView mIvImage2;
        TextView mTvToday;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
            mTvDateperiod = itemView.findViewById(R.id.tvDateperiod);
            mTvExplain = itemView.findViewById(R.id.tvExplain);
            mIvImage1 = itemView.findViewById(R.id.ivImage1);
            mIvImage2 = itemView.findViewById(R.id.ivImage2);
            mTvToday = itemView.findViewById(R.id.tvToday);
        }
    }

    public interface OnSelectPatrolListener {
        void onSuccess(Patrol patrol);
    }
}
